package cn.qidisoft.edu.hzjt.service.zyc.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.zyc.DevelopmentPlanningMapper;
import cn.qidisoft.edu.hzjt.model.zyc.DevelopmentPlanning;
import cn.qidisoft.edu.hzjt.model.zyc.PartyLeagueMember;
import cn.qidisoft.edu.hzjt.model.zyc.SchoolMagazine;
import cn.qidisoft.edu.hzjt.service.zyc.IDevelopmentPlanningService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 学校发展规划Service实现层
 * @author zhangwenliang
 *@Date 2018.11.27
 */
@Service
public class DevelopmentPlanningServiceImpl implements IDevelopmentPlanningService{

    protected static final LoggerAdapter LOGGER = LoggerAdapterFactory
            .getLogger(LogType.HZJT_LOGGER.val); 
	
	
	@Autowired
	private DevelopmentPlanningMapper developmentPlanningMapper;
	
	@Override
	public PaginationBean<DevelopmentPlanning> queryPageList(Map<String, Object> data, Page page) {
		try {
            int c = developmentPlanningMapper.queryPageListcount(data);
            int totalRecords = c;
            PaginationBean<DevelopmentPlanning> pageHolder = new PaginationBean<>(page, totalRecords);
            List<DevelopmentPlanning> resultList = developmentPlanningMapper.queryPageList(data,
                            new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                                    pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
                    this.getClass().getName(),
                    ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                    e);
        }
	}

	@Override
	public int delete(DevelopmentPlanning record) {
	       return developmentPlanningMapper.delete(record);
	}

	@Override
	public List<DevelopmentPlanning> getPlanningList(Map<String, Object> queryMap) {
		return developmentPlanningMapper.getPlanningList(queryMap);
	}
	
	
	
	
	public Integer insert(DevelopmentPlanning record) {
		developmentPlanningMapper.insert(record);
        if (StringUtils.isNotEmpty(record.getGid())){
        	DevelopmentPlanning nr = queryByPK(record);
            if (nr!=null&&nr.getFzid()!=null) {
                int newid = nr.getFzid();
                record.setFzid(newid);
                return newid;
            }
        }
        return null;
    }

	@Override
	public DevelopmentPlanning queryByPK(DevelopmentPlanning record) {
		
		return developmentPlanningMapper.queryByPK(record);
	}

	@Override
	public DevelopmentPlanning getPlanning(DevelopmentPlanning development) {
		
		return developmentPlanningMapper.getPlanning(development);
	}

	public void update(DevelopmentPlanning data) {
		developmentPlanningMapper.update(data);
		
	}
}
